<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>03_JS数据类型</title>
</head>
<body>
<script>
    //JS数据类型 = 原始类型+引用类型
    //原始类型：number string boolean  undefined null
    //引用类型:Object function array date...
    var a = 1;
    var b = 3.6;
    console.log(a,typeof a,b,typeof b);  //整数小数都是number
    var c = 'hello';
    var d = "你好呀";
    console.log(c,typeof c,d,typeof d);  //单引双引都是string
    var e = true;
    var f = false;
    console.log(e,typeof e,f,typeof f);  //true与false是布尔
    var g;
    console.log(g,typeof g);  //声明了变量但未赋值推断不出来类型，是未定义型undefined

    //引用类型：定义一个自定义的JS对象
    let obj = {};
    console.log(obj,typeof obj);  //{} object
    let obj2 = {
        name:'张三',
        age:18
    };
    console.log(obj2,typeof obj2); // {name:'张三',age：18} 'object'
    console.log(obj2.name,obj2.age);
    obj2.like = '吃火锅';  //可以后期动态新增属性，但注意必须赋值！
    console.log(obj2.like);
    console.log(obj2,typeof obj2);  //{name: '张三', age: 18} 'object'
    console.log(obj2.play);  //undefined

    //JS数组
    let arr = ['张三',18,true,6.6];
    console.log(arr,typeof arr);  //(4) ['张三', 18, true, 6.6] 'object'
    console.log(arr[0]);  //'张三'
    console.log(arr[3]);  // 6.6
    console.log(arr[33]);  //undefined

    //Boolean()用于将参数转为布尔类型
    //0,undefined,null,空字符串,NaN这5个特殊值转为布尔都是false
    console.log(Boolean(0));
    console.log(Boolean(undefined));
    console.log(Boolean(null));
    console.log(Boolean(''));
    console.log(Boolean(NaN));
    console.log('--------------------');
    console.log(Boolean(1));
    console.log(Boolean(' '));
    console.log(Boolean('hello'));

    //Number()用于将参数转为数值类型
    //如果得不到数字类型的结果，就会得到NaN(Not a number)
    console.log(Number(true),typeof Number(true));
    console.log(Number(false),typeof Number(true));
    console.log(Number(3));
    console.log(Number('3'),typeof Number('3'));
    console.log(Number('哈哈哈'),typeof Number('哈哈哈'));



</script>
</body>
</html>